package com.hnu.tockmarket.activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.hnu.tockmarket.R;

/**
 * 意见反馈页面对应的活动
 *
 * @author hnulht
 * @since 2021-07-09
 */
public class UserAdviceActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "UserChangePasswordActivity"; // 日志
    private EditText editTextAdvice; // 用户意见反馈输入框
    private Button buttonSubmit; // 提交按钮
    private Button buttonClear; // 清空按钮
    private Toolbar toolbar; // 工具栏
    private ProgressDialog progressDialog; // 提交加载控件

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); // 调用父类onCreate()方法
        setContentView(R.layout.activity_user_advice); // 给意见反馈页面活动加载对应的布局
        initView(); // 初始化视图
    }

    /**
     * 初始化视图
     */
    private void initView() {
        // 定位工具栏并设置点击事件
        toolbar = (Toolbar) findViewById(R.id.user_advice_tb);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        // 定位用户意见反馈输入框
        editTextAdvice = (EditText) findViewById(R.id.user_advice_et);
        // 定位用户提交按钮并设置点击事件
        buttonSubmit = (Button) findViewById(R.id.user_advice_submit_btn);
        buttonSubmit.setOnClickListener(this);
        // 定位清空按钮并设置点击事件
        buttonClear = (Button) findViewById(R.id.user_advice_clear_btn);
        buttonClear.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.user_advice_submit_btn:
                // 定位提交加载控件并设置延时取消
                progressDialog = new ProgressDialog(UserAdviceActivity.this);
                progressDialog.setMessage("提交中...");
                progressDialog.setCancelable(false);
                progressDialog.show();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(2000); // 显示2秒后取消加载
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        progressDialog.dismiss();
                        finish();
                    }
                }).start();
                break;
            case R.id.user_advice_clear_btn:
                editTextAdvice.setText("");
                editTextAdvice.setText("");
                break;
        }
    }

}